package mzt;

import java.util.concurrent.TimeUnit;

public class DownThread implements Runnable {
	private String urlStr, file;

	public DownThread(String urlStr, String file) {
		super();
		this.urlStr = urlStr;
		this.file = file;
		Thread thread = new Thread(this);
		thread.setUncaughtExceptionHandler(new DownUncaugthEx());
		thread.start();
	}

	private class DownUncaugthEx implements Thread.UncaughtExceptionHandler {

		@Override
		public void uncaughtException(Thread t, Throwable e) {
			System.out.println("===========下载中断重新下载" + urlStr + "==========保存位置是" + file);
			try {
				TimeUnit.MILLISECONDS.sleep(100);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
			// new DownThread(urlStr, file);
			System.out.println("DownThread.DownUncaugthEx.uncaughtException()");
		}
	}

	@Override
	public void run() {
		try {
			// System.out.println(urlStr);
			Utils.down(urlStr, file);

		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("淡泊明志，宁静致远");
		}
	}

}
